﻿using AppManager.BLL;
using AppManager.Model;
using System;
using System.Web.Mvc;

namespace PushManager.Web.Controllers
{
    /// <summary>
    /// controllers裡面的兩個方法負責添加項目信息和接收一些
    /// </summary>
    public class MessageController : Controller
    {
        /// <summary>
        /// 語义话的api是我下一个追求
        /// 加上一個限制，message.data必須是json格式
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public ActionResult Add(AddMessageModel model)
        {
            try
            {
                model.Message = Server.UrlDecode(model.Message);
                MessageBLL.AddOrUpdate(model);
                return Json(new ApiResult { status = 100, msg = "操作成功" });
            }
            catch (Exception ex)
            {
                return Json(new ApiResult { status = 500, msg = ex.Message });
            }
        }

        public ActionResult AddOld(AddOldMessageModel model)
        {
            try
            {
                //转化下
                var message = new AddMessageModel
                {
                    AppName = model.AppName,
                    Data = model.Data,
                    Message = Server.UrlDecode(model.Message),
                    GoogleList = model.aztokenList,
                    IosList = model.iostokenlist,
                };
                MessageBLL.AddOrUpdate(message);
                return Json(new ApiResult { status = 100, msg = "操作成功" });
            }
            catch (Exception ex)
            {
                return Json(new ApiResult { status = 500, msg = ex.Message });
            }
        }
    }
}